Skip to content

Conversation

@darioAnongba
Copy link
Contributor

@darioAnongba darioAnongba commented Oct 1, 2025

Garbage collect the residue orphaned UTXOs when creating transactions. Orphaned UTXOs occur when creating tombstones or full burns.
Currently, these UTXOs accumulate in the DB and are never cleaned. This PR introduces a garbage collection mechanism to collect these UTXOs and use them as inputs of transactions initiated by tapd:

  • Transfers
  • Burns

The PR adds a new swept flag to the managed_utxo table because UTXOs are not removed from the table when spent. This flag is also returned by the ListUtxos RPC endpoint.

The mechanism preserves the liveness and safety properties, ensuring that zero-value UTXOs can never accumulate in the DB. Adding garbage collection to Mint transactions is not necessary to ensure these properties.

Fixes #514

Note to reviewers

  1. UTXO meaning unspent, keeping the spent outputs in a table called manage_utxos seems like a contradiction, same logic applies for the need of a swept flag in that table. We should either rename the table or store spent utxos somewhere else?

@darioAnongba darioAnongba self-assigned this Oct 1, 2025
@coveralls
Copy link

coveralls commented Oct 1, 2025

Pull Request Test Coverage Report for Build 18946918516

Details

  • 292 of 377 (77.45%) changed or added relevant lines in 16 files are covered.
  • 54 unchanged lines in 18 files lost coverage.
  • Overall coverage increased (+0.09%) to 56.613%

Changes Missing Coverage Covered Lines Changed/Added Lines %
asset/asset.go 3 5 60.0%
itest/assertions.go 0 3 0.0%
rpcserver.go 10 15 66.67%
tapfreighter/chain_porter.go 40 45 88.89%
tapfreighter/coin_select.go 23 29 79.31%
tapfreighter/wallet.go 55 76 72.37%
tapdb/assets_store.go 101 144 70.14%
Files with Coverage Reduction New Missed Lines %
proof/courier.go 1 79.81%
address/mock.go 2 96.2%
asset/group_key.go 2 72.15%
mssmt/compacted_tree.go 2 77.19%
tapdb/mssmt.go 2 89.55%
tapdb/multiverse.go 2 80.85%
taprpc/universerpc/universe_grpc.pb.go 2 65.45%
universe_rpc_diff.go 2 77.33%
universe/supplyverifier/manager.go 2 64.53%
universe/syncer.go 2 85.5%
Totals Coverage Status
Change from base Build 18942913401: 0.09%
Covered Lines: 64610
Relevant Lines: 114125

💛 - Coveralls

@levmi levmi moved this from 🆕 New to 🏗 In progress in Taproot-Assets Project Board Oct 2, 2025
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch from f3a3bff to f55b6c5 Compare October 3, 2025 16:21
@darioAnongba darioAnongba changed the base branch from main to 0-8-0-staging October 6, 2025 09:43
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch 3 times, most recently from 3bd769d to 6fe11a5 Compare October 6, 2025 15:03
@darioAnongba darioAnongba changed the base branch from 0-8-0-staging to main October 6, 2025 15:03
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch 10 times, most recently from a8f3ce4 to afbfebf Compare October 9, 2025 13:04
@darioAnongba darioAnongba marked this pull request as ready for review October 9, 2025 13:09
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch 4 times, most recently from bf3e3ee to d812a8e Compare October 9, 2025 16:04
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch from d812a8e to 0ceaf76 Compare October 9, 2025 16:32
@darioAnongba darioAnongba moved this from 🏗 In progress to 👀 In review in Taproot-Assets Project Board Oct 9, 2025
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch 4 times, most recently from faf184a to d52a498 Compare October 27, 2025 15:29
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch from d52a498 to 6edd03c Compare October 27, 2025 18:04
@ffranr
Copy link
Contributor

ffranr commented Oct 28, 2025

Non-blocking, but for the sweepZeroValueAnchorUtxos config field: “sweep orphaned UTXOs” might be clearer. “Anchor” is implied by UTXO, and “zero-value” isn’t accurate since they contain 1000 sats. If they were zero value there would be nothing to sweep.

@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch 3 times, most recently from 5635183 to 0b60ce3 Compare October 28, 2025 17:41
@darioAnongba
Copy link
Contributor Author

I like SweepOrphanUtxos better as well. I renamed it everywhere at the config level, let me know if you think we should rename all the way down to the DB layer. In the context of assets, zero-value is correct though, but more verbose and uglier.

@darioAnongba darioAnongba requested a review from ffranr October 28, 2025 17:43
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch 4 times, most recently from ef93717 to d9383ba Compare October 28, 2025 18:58
Copy link
Member

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last nits, 99% there

@ffranr ffranr added this to the v0.8 milestone Oct 30, 2025
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch from d9383ba to 773c448 Compare October 30, 2025 13:26
Copy link
Member

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch from 773c448 to 4fb0135 Compare October 30, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

wallet: garbage collect tombstone UTXOs

5 participants